package com.controller;

import com.domain.Addresslist;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.AddresslistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@org.springframework.stereotype.Controller
public class Controller {
    @Autowired
    private AddresslistService addresslistService;
    @RequestMapping("/findAll")
    public String findAll(@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "4")int size, Model model){
        PageHelper.startPage(page,size);
        List<Addresslist> all = addresslistService.findAll();
        PageInfo<Addresslist> pageInfo = new PageInfo<>(all);
        model.addAttribute("all",all);
        model.addAttribute("ps",pageInfo);
        return "show";
    }
    @RequestMapping("/insert")
    public String insert(Addresslist addresslist){
        addresslistService.insert(addresslist);
        return "redirect:findAll";
    }
}
